//
//  ZToolsView.m
//  danpin
//
//  Created by chuangjia on 29/7/15.
//  Copyright (c) 2015 chuangjia. All rights reserved.
//

#import "ZToolsView.h"
#import "BaseCell.h"
@implementation ZToolsView

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        [self setFrame:frame];
        [self initUIWithType:0];
    }
    return self;
}

-(void)layoutSubviews
{
    [super layoutSubviews];
    
}
-(void)dealloc
{
    
    self.actionBlock=nil;
    self.newdp=nil;
    self.qgdp=nil;
}

-(void)setCallBack:(void(^)(ToolEventType,UIView *,id,id))callback
{
    self.actionBlock =callback;
}
-(void)initUIWithType:(int)type
{
    UIView *bgView =[[UIView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
    bgView.backgroundColor=[UIColor clearColor];
    [self addSubview:bgView];
    
    //
    UIImageView *bgImageView =[[UIImageView alloc] initWithFrame:bgView.frame];
    bgImageView.image =[UIImage imageNamed:@"toolbar_bg.png"];
    [bgView addSubview:bgImageView];
    
    UIButton *back =[UIButton buttonWithType:UIButtonTypeCustom];
    back.frame =CGRectMake(PHOTO_FRAME_WIDTH, hightAuto(7.5), widthAuto(30), hightAuto(30));
    back.backgroundColor=[UIColor clearColor];
    back.tag=0;
    [back setImage:[UIImage imageNamed:@"toolbar_back.png"] forState:UIControlStateNormal];
    [back setImage:[UIImage imageNamed:@"toolbar_back.png"] forState:UIControlStateSelected];
    [back setImage:[UIImage imageNamed:@"toolbar_back.png"] forState:UIControlStateHighlighted];
    [back addTarget:self action:@selector(clickEvent:) forControlEvents:UIControlEventTouchUpInside];
    [bgView addSubview:back];
    
    UIButton *refresh =[UIButton buttonWithType:UIButtonTypeCustom];
    refresh.tag=1;
    refresh.frame =CGRectMake(PHOTO_FRAME_WIDTH*2+widthAuto(30), hightAuto(7.5), widthAuto(30), hightAuto(30));
    refresh.backgroundColor=[UIColor clearColor];
    [refresh setImage:[UIImage imageNamed:@"toolbar_refresh.png"] forState:UIControlStateNormal];
    [refresh setImage:[UIImage imageNamed:@"toolbar_refresh.png"] forState:UIControlStateSelected];
    [refresh setImage:[UIImage imageNamed:@"toolbar_refresh.png"] forState:UIControlStateHighlighted];
    [refresh addTarget:self action:@selector(clickEvent:) forControlEvents:UIControlEventTouchUpInside];
    [bgView addSubview:refresh];
    
    _newdp =[UIButton buttonWithType:UIButtonTypeCustom];
    _newdp.tag=2;
    _newdp.frame =CGRectMake(DEVICE_WIDTH-PHOTO_FRAME_WIDTH-widthAuto(80), hightAuto(7.5), widthAuto(80), hightAuto(30));
    _newdp.backgroundColor=[UIColor clearColor];
    [_newdp setImage:[UIImage imageNamed:@"toolbar_newdp_normal.png"] forState:UIControlStateNormal];
    [_newdp setImage:[UIImage imageNamed:@"toolbar_newdp_hover.png"] forState:UIControlStateSelected];
    [_newdp setImage:[UIImage imageNamed:@"toolbar_newdp_hover.png"] forState:UIControlStateHighlighted];
    [_newdp addTarget:self action:@selector(clickEvent:) forControlEvents:UIControlEventTouchUpInside];
    _newdp.hidden=YES;
    [bgView addSubview:_newdp];
    
    _qgdp =[UIButton buttonWithType:UIButtonTypeCustom];
    _qgdp.tag=3;
    _qgdp.frame =CGRectMake(DEVICE_WIDTH-PHOTO_FRAME_WIDTH-widthAuto(80), hightAuto(7.5), widthAuto(80), hightAuto(30));
    _qgdp.backgroundColor=[UIColor clearColor];
    [_qgdp setImage:[UIImage imageNamed:@"toolbar_qgdp_normal.png"] forState:UIControlStateNormal];
    [_qgdp setImage:[UIImage imageNamed:@"toolbar_qgdp_hover.png"] forState:UIControlStateSelected];
    [_qgdp setImage:[UIImage imageNamed:@"toolbar_qgdp_hover.png"] forState:UIControlStateHighlighted];
    [_qgdp addTarget:self action:@selector(clickEvent:) forControlEvents:UIControlEventTouchUpInside];
    [bgView addSubview:_qgdp];
    
}
-(void)clickEvent:(id)sender
{
    UIButton*btn =(UIButton*)sender;
    ToolEventType type=ToolEventType_unknow;
    switch (btn.tag) {
        case 0:
        {
            type =ToolEventType_back;
        }
            break;
        case 1:
        {
            type =ToolEventType_refresh;
        }
            break;
        case 2:
        {
            type =ToolEventType_newdp;
        }
            break;
        case 3:
        {
            type =ToolEventType_qgdp;
        }
            break;
        default:
            break;
    }
    if (self.actionBlock) {
        self.actionBlock(type,self,nil,nil);
    }
}
@end
